import asyncio
import sys
print(sys.path)
from util import delay


async def hello_interval(num, interval):
    for i in range(num):
        n = i + 1
        await asyncio.sleep(interval)
        print(f'Hello no.{n}')


async def main():
    
    N = 2  # Tasks sleep1~3 end before hello_interval
    # N = 6  # Tasks after hello_interval
    
    sleep1 = asyncio.create_task(delay(N, 'Sleep 1'))
    print('sleep1:', sleep1, type(sleep1))
    
    sleep2 = asyncio.create_task(delay(N, 'Sleep 2'))
    print('sleep2:', sleep2, type(sleep2))
    
    sleep3 = asyncio.create_task(delay(N, 'Sleep 3'))
    print('sleep3:', sleep3, type(sleep3))

    await hello_interval(15, 0.2)
    
    print('Before await the tasks.')
    result = await sleep1
    print('result 1:', result)
    result = await sleep2
    print('result 2:', result)
    result = await sleep3
    print('result 3:', result)
    
    print('All over')
    
    
if '__main__' == __name__:
    
    asyncio.run(main())
    